package com.mge.ae.views.editor;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.nebula.widgets.pshelf.PShelf;
import org.eclipse.nebula.widgets.pshelf.PShelfItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;

import com.mgetool.test.TestCanvas;
import com.mgetool.ui.CanvasComposite;

public class ImageTileEditor extends EditorPart {

	public static final String ID = "com.mge.ae.views.editor.ImageTileEditor"; //$NON-NLS-1$
	private CanvasComposite canvasComposite;
	
	public ImageTileEditor() {
	}

	/**
	 * Create contents of the editor part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		parent.setLayout(new GridLayout(1, false));
		{
			ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.RIGHT | SWT.SHADOW_OUT);
			toolBar.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
			{
				ToolItem tltmNewItem = new ToolItem(toolBar, SWT.NONE);
				tltmNewItem.setText("New Item");
			}
			{
				ToolItem tltmNewItem_1 = new ToolItem(toolBar, SWT.SEPARATOR);
				tltmNewItem_1.setText("New Item");
			}
			{
				ToolItem tltmNewItem_2 = new ToolItem(toolBar, SWT.NONE);
				tltmNewItem_2.setText("New Item");
			}
		}
		
		SashForm sashForm = new SashForm(parent, SWT.NONE);
		sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
		
		ScrolledComposite scrolledComposite = new ScrolledComposite(sashForm, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		PShelf shelf_1 = new PShelf(scrolledComposite, SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
		
		
		PShelfItem shelfItem_2 = new PShelfItem(shelf_1, 0);
		shelfItem_2.setText("New Item");
		shelfItem_2.getBody().setLayout(new FillLayout(SWT.HORIZONTAL));
		
		Composite composite_1 = new Composite(shelfItem_2.getBody(), SWT.NONE);
		composite_1.setLayout(new GridLayout(2, true));
		
		Button button_6 = new Button(composite_1, SWT.NONE);
		button_6.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		button_6.setText("New Button");
		
		Button button_7 = new Button(composite_1, SWT.NONE);
		button_7.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		button_7.setText("New Button");
		
		Button button_8 = new Button(composite_1, SWT.NONE);
		button_8.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		button_8.setText("New Button");
		
		Button button_9 = new Button(composite_1, SWT.NONE);
		button_9.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		button_9.setText("New Button");
		
		Button button_10 = new Button(composite_1, SWT.NONE);
		button_10.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		button_10.setText("New Button");
		
		Button button_11 = new Button(composite_1, SWT.NONE);
		button_11.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		button_11.setText("New Button");
		
		PShelfItem shelfItem_3 = new PShelfItem(shelf_1, 0);
		shelfItem_3.setText("New Item");
		shelfItem_3.getBody().setLayout(new FillLayout(SWT.HORIZONTAL));
		
		Composite composite_4 = new Composite(shelfItem_3.getBody(), SWT.NONE);
		composite_4.setLayout(new GridLayout(2, true));
		
		Button button_12 = new Button(composite_4, SWT.NONE);
		button_12.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		button_12.setText("New Button");
		
		Button button_13 = new Button(composite_4, SWT.NONE);
		button_13.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		button_13.setText("New Button");
		
		Button button_14 = new Button(composite_4, SWT.NONE);
		button_14.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		button_14.setText("New Button");
		
		Button button_15 = new Button(composite_4, SWT.NONE);
		button_15.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		button_15.setText("New Button");
		
		Button button_16 = new Button(composite_4, SWT.NONE);
		button_16.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		button_16.setText("New Button");
		
		Button button_17 = new Button(composite_4, SWT.NONE);
		button_17.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		button_17.setText("New Button");
		scrolledComposite.setContent(shelf_1);
		scrolledComposite.setMinSize(shelf_1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		canvasComposite = new CanvasComposite(sashForm, SWT.BORDER);
		canvasComposite.getPageManager().push(new TestCanvas(canvasComposite.getDisplay()));
		
		
		
		sashForm.setWeights(new int[] {179, 402});

		PShelfItem[] controls = shelf_1.getItems();
		if(controls != null){
			for(int i = 0; i < controls.length; i++){
				PShelfItem item = (PShelfItem)controls[i];
				shelf_1.setSelection(item);
				System.out.println("@@@@@@@@@@@@@");
			}
		}
		

	}
	

	@Override
	public void setFocus() {
		// Set the focus
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		// Do the Save operation
	}

	@Override
	public void doSaveAs() {
		// Do the Save As operation
	}

	@Override
	public void init(IEditorSite site, IEditorInput input)
			throws PartInitException {
		// Initialize the editor part
	}

	@Override
	public boolean isDirty() {
		return false;
	}

	@Override
	public boolean isSaveAsAllowed() {
		return false;
	}

}
